//
//  buyOperation.h
//  alotOf
//
//  Created by Mac_Black_Mini on 2025/9/3.
//

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>

NS_ASSUME_NONNULL_BEGIN
// 内购状态枚举
typedef NS_ENUM(NSInteger, IAPStatus) {
    IAPStatusSuccess,       // 购买成功
    IAPStatusFailed,        // 购买失败
    IAPStatusCancelled,     // 取消购买
    IAPStatusVerified,      // 验证成功
    IAPStatusUnverified,    // 验证失败
    IAPStatusRestored,      // 恢复购买
    IAPStatusNoProducts     // 没有获取到产品
};

// 内购结果回调
typedef void(^IAPCompletion)(IAPStatus status, NSDictionary * _Nullable info, NSError * _Nullable error);

@interface BuyOperation : NSObject<SKProductsRequestDelegate, SKPaymentTransactionObserver>
// 单例
+ (instancetype)sharedInstance;

- (void)requestProductInformation;
/**
 请求商品列表
 
 @param productIds 商品ID数组
 @param completion 回调
 */
- (void)requestProductsWithIds:(NSArray<NSString *> *)productIds completion:(IAPCompletion)completion;
/**
 购买商品
 
 @param product 商品对象
 @param completion 回调
 */
- (void)purchaseProduct:(SKProduct *)product completion:(IAPCompletion)completion;

/**
 恢复购买
 
 @param completion 回调
 */
- (void)restorePurchasesWithCompletion:(IAPCompletion)completion;

/**
 验证交易凭证
 
 @param receiptData 凭证数据
 @param isSandbox 是否沙盒环境
 @param completion 回调
 */
- (void)verifyReceipt:(NSData *)receiptData isSandbox:(BOOL)isSandbox completion:(IAPCompletion)completion;
@end

NS_ASSUME_NONNULL_END
